home *** CD-ROM | disk | FTP | other *** search
- /*
- * Copyright (C) 1994, Silicon Graphics, Inc.
- * All Rights Reserved.
- *
- * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, Inc.;
- * the contents of this file may not be disclosed to third parties, copied or
- * duplicated in any form, in whole or in part, without the prior written
- * permission of Silicon Graphics, Inc.
- *
- * RESTRICTED RIGHTS LEGEND:
- * Use, duplication or disclosure by the Government is subject to restrictions
- * as set forth in subdivision (c)(1)(ii) of the Rights in Technical Data
- * and Computer Software clause at DFARS 252.227-7013, and/or in similar or
- * successor clauses in the FAR, DOD or NASA FAR Supplement. Unpublished -
- * rights reserved under the Copyright Laws of the United States.
- */
-
- /*
- * fontCursor.c
- *
- * a simple example of changing a window's cursor using "Font" cursors.
- * The cursors are refered to by an index which is defined in the include
- * file <X11/cursorfont.h>. Viewing cursor font definitions is possible
- * by using the utility `xfd' like so:
- *
- * xfd -fn cursor
- */
-
- #include <unistd.h>
- #include <stdio.h>
- #include <string.h>
- #include <X11/Xlib.h>
- #include <X11/Xutil.h>
- #include <X11/cursorfont.h>
-
- main(void)
- {
- Display *dpy;
- Window wind;
- int scr;
- unsigned int keep_going = 1;
- XEvent ev;
- unsigned int i;
- XColor backg, ebackg, foreg, eforeg, ered, red;
- Window rwin;
- Colormap dcm;
- GC dgc;
- Cursor fontc[XC_num_glyphs];
- unsigned char id[256];
- static unsigned char drexions[] = "Mouse button to cycle thru Font Cursors.";
- XWMHints wmhints;
- XSizeHints wmsizehints;
- XClassHint classhint;
-
- dpy = XOpenDisplay("");
- scr = DefaultScreen(dpy);
- rwin = RootWindow(dpy, scr);
- dcm = DefaultColormap(dpy, scr);
- dgc = DefaultGC(dpy,scr);
-
- #if defined(DEBUGIT)
- XSynchronize(dpy,True);
- #endif
- if( !XAllocNamedColor(dpy, dcm, "darkslategray", &backg, &ebackg)) {
- fprintf( stderr, "Error getting DarkSlateGray\n" ); exit(1); }
-
- if( !XAllocNamedColor(dpy, dcm,"ivory", &foreg, &eforeg)) {
- fprintf( stderr, "Error getting Ivory\n" ); exit(1); }
-
- if( !XAllocNamedColor(dpy, dcm,"red", &red, &ered)) {
- fprintf( stderr, "Error getting Red\n" ); exit(1); }
-
- for( i = 0; i < XC_num_glyphs-1; i++ ) {
- #if defined(DEBUGIT)
- printf("%d\n", i); fflush(stdout);
- #endif
- fontc[i] = XCreateFontCursor(dpy, i);
- if( fontc[i] == NULL ) {
- fprintf( stderr, "Error creating cursor from cursorfont %d\n", i );
- exit(1);
- }
- XRecolorCursor( dpy, fontc[i], &foreg, &red );
- }
-
- wind = XCreateSimpleWindow( dpy, rwin, 0, 0, 512, 512, 2,
- foreg.pixel, backg.pixel);
-
- classhint.res_name = "LEFT or RIGHT Mouse to Change Cursor";
- classhint.res_class = "GlyphCursor";
- XSetClassHint(dpy, wind, &classhint);
-
- wmhints.input = True;
- wmhints.flags = InputHint;
- XSetWMHints(dpy, wind, &wmhints);
-
- wmsizehints.x = 100;
- wmsizehints.y = 100;
- wmsizehints.width = 100;
- wmsizehints.height = 100;
- wmsizehints.flags = USPosition | USSize;
- XSetWMNormalHints(dpy, wind, &wmsizehints);
-
- XSetWindowBackground( dpy, wind, backg.pixel );
- XSetBackground( dpy, dgc, red.pixel );
- XSetForeground( dpy, dgc, foreg.pixel );
-
- XSelectInput( dpy, wind, ButtonPressMask|KeyPressMask|ExposureMask);
- XMapWindow( dpy, wind );
-
- i = 0;
- do {
- XNextEvent( dpy, &ev );
- switch( ev.type )
- {
- case Expose:
- while( XCheckTypedEvent(dpy, Expose, &ev) );
- XUndefineCursor( dpy, wind );
- XClearWindow(dpy, wind);
- XDefineCursor( dpy, wind, fontc[i%(XC_num_glyphs-1)] );
- sprintf(id, "%d", i%(XC_num_glyphs-1));
- XDrawString(dpy, wind, dgc, 200, 200, id, strlen(id));
- XDrawString(dpy, wind, dgc, 20, 20, drexions, strlen(drexions));
- break;
-
- case KeyPress:
- XCloseDisplay(dpy);
- keep_going = 0;
- break;
-
- case ButtonPress:
- if( ev.xbutton.button == Button1 )
- i += 1;
- else if( ev.xbutton.button == Button3 )
- i -= 1;
- else
- i = 0;
- XUndefineCursor( dpy, wind );
- XClearWindow(dpy, wind);
- XDefineCursor( dpy, wind, fontc[i%(XC_num_glyphs-1)] );
- sprintf(id, "%d", i%(XC_num_glyphs-1));
- XDrawString(dpy, wind, dgc, 200, 200, id, strlen(id));
- XDrawString(dpy, wind, dgc, 20, 20, drexions, strlen(drexions));
- break;
-
- default:
- break;
- }
- } while( keep_going );
- exit(0);
- }
-